<?php
	session_start();
	if(!isset($_SESSION['login'])){
		header('location:../vue/index.php');
	}
	include 'navBar.php';
	$myvar = new SQLBlog();
	if($var_post=$myvar->AfficherUnPost($_GET['art_id'])){

?>

<html>

<head>
	<title>BLOG</title>
	<meta charset="utf8">
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
	<script src="http://tinymce.cachefly.net/4.1/tinymce.min.js"></script>
		
	
	<script type="text/javascript">

		$(window).load(function(){
			function readURL(input) {
				if (input.files && input.files[0]) {
					var reader = new FileReader();
					
					reader.onload = function (e) {
						$('#blah').attr('src', e.target.result);
					}
					
					reader.readAsDataURL(input.files[0]);
				}
			}
			
			$("#imgInp").change(function(){
				readURL(this);
			});
		}); 
		
		tinymce.init({selector: "textarea",setup: function (editor) {editor.on('change', function () {tinymce.triggerSave();});}});
		
    </script>


	<style type="text/css">
	
	.content{
		margin:5% 10% 0 10%;
	}
	.background-img{
		position:abs;
		z-index: -1;
		overflow:visible;

		height:auto;
		min-height:100vh;
		
		-webkit-filter: blur(5px);
		-moz-filter: blur(5px);
		-o-filter: blur(5px);
		-ms-filter: blur(5px);
		filter: blur(5px);
	}
	
	.navbar{
				-webkit-box-shadow: 0px 4px 15px 0px rgba(0,0,0,0.75);
				-moz-box-shadow: 0px 4px 15px 0px rgba(0,0,0,0.75);
				box-shadow: 0px 4px 15px 0px rgba(0,0,0,0.75);
			}
	
	label{
                margin:0 5px 0 0;
				color:white;
            }
	
	body{
	   min-width:800px;
	   width:auto!important;
	   width:800px;
	   height:5000px;
	   background-image:url(../img/sharp_edge.png);
       background-repeat:repeat;
	}
	</style>
	
</head>

<body>
	<div style="margin-top:50px;">
		<fieldset style="margin:150px 5% 0 5%">
                <form method="POST" action="../controleur/submit_modif.php" runat="server" enctype="multipart/form-data">
                    <select name="art_cat" class="form-control">
                        <?php
                        $myvar = new SQLBlog();
                        if ($var = $myvar->AfficherCategories()) {
                            foreach ($var as $line) {
                                echo "<option value=\"" . $line['id'] . "\" ".($var_post[0]['id_categorie']==$line['id']?"selected":"") .">" . $line['nom'] . "</option>";
                            }
                        }
                        ?>
                    </select>
                    <input type="text" class="form-control" placeholder="Nouvelle Categorie" name="cat_new" id="cat_new" style="width:inherit;display:inline;margin:5px 0 30px 0;"/>
                    <button type="button" name="newcat" class="btn btn-primary btn-success" value="Ajouter" onclick="recupinput()"><span class="glyphicon glyphicon-plus"></span></button>
                    <input type="text" class="form-control" placeholder="Titre" name="art_titre" value=<?php echo '"'.$var_post[0]['titre'].'"';?> required/><br/>
                    <textarea type="text" class="form-control" placeholder="Contenu" name="art_contenu" rows="20" required><?php echo $var_post[0]['texte'];?></textarea><br>
                    <input type="file" id="imgInp" name="pj" accept=".jpg,.png,.gif,.jpeg" style="color:white;"/><br/>
					<img id="blah" name="blah" style="width:500px;" src="<?php if($var_post[0]['piecesJointes']) echo $var_post[0]['piecesJointes']; ?>" alt="Votre image"/><br/><br/>
					<input type="hidden" name="pjbackup" value="<?php if($var_post[0]['piecesJointes']) echo $var_post[0]['piecesJointes']; ?>"/>
					<label>Post visible ?</label><input type="checkbox" name="art_actif" <?php echo($var_post[0]['actif']=="1"?"checked":"");?>/><br/>
                    <label>Commentaire autorisés ?</label><input type="checkbox" name="art_comm" <?php echo($var_post[0]['commentaireAutorise']=="1"?"checked":"");?>/><br/>
					<input type="hidden" name="art_id" value="<?php echo $var_post[0]['id'];?>"/>
                    <input type="submit" name="valid_post" value="Sauvegarder" class="btn btn-primary btn-success"/>
                </form>
            </fieldset>
	</div>

</body>
</html>
<?php	
	
	}else var_dump($var_post);
?>